#include "HelloWorldScene.h"

using namespace cocos2d;

CCScene* MainView::scene()
{
    CCScene * scene = NULL;
    do 
    {
        // 'scene' is an autorelease object
        scene = CCScene::create();
        CC_BREAK_IF(! scene);

        // 'layer' is an autorelease object
        MainView *layer = MainView::create();
        CC_BREAK_IF(! layer);

        // add layer as a child to scene
        scene->addChild(layer);
    } while (0);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool MainView::init()
{
    bool bRet = false;
    do 
    {
        CC_BREAK_IF(! CCLayer::init());
 
		CCSize size = CCDirector::sharedDirector()->getWinSize();

        CCMenuItemImage *pInfoItem = CCMenuItemImage::create(
            "Icon.png",
            "Icon.png",
            this,
            menu_selector(MainView::menuInfoCallback));
        CC_BREAK_IF(! pInfoItem);
        pInfoItem->setPosition(ccp(100, 200));
        

		CCMenuItemImage *pFightItem = CCMenuItemImage::create(
			"Icon.png",
			"Icon.png",
			this,
			menu_selector(MainView::menuFightCallback));
		CC_BREAK_IF(! pFightItem);
		pFightItem->setPosition(ccp(size.width - 50, 350));


		//CCLabelTTF* plabel = CCLabelTTF::create("CCCCCCCCCCC", "AppleGothic", 23);
		//ccColor3B color;
		//color.b = 12;
		//color.g = 23;
		//color.r = 55;
		//plabel->setColor(color);
		//plabel->setPosition(ccp(233, 233));
		//this->addChild(plabel, 2);
	
		CCMenu* pMenu = CCMenu::create(pInfoItem, pFightItem, NULL);
        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);
        this->addChild(pMenu, 11);

      
        CCSprite* pSprite = CCSprite::create("welcome.jpg");
        CC_BREAK_IF(! pSprite);
        pSprite->setPosition(ccp(size.width / 2, size.height / 2));
        this->addChild(pSprite, 0);


		//player = new PlayerOne();
		//PlayerOne* player = new PlayerOne();
		//player->setName("balabala");
		//player->setAge(23);
		//player->setAssets(8888);
		//player->setDamageValue(50);
		//player->setDefence(10);
		//player->setHP(1000);
		//player->setExperience(10086);
		//player->setGrade(10);
		//player->setMagicValue(100);
		//
		//
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("bk.mp3", true);

        bRet = true;
    } while (0);

    return bRet;
}

void MainView::menuInfoCallback(CCObject* pSender)
{
	CCScene* scene = InfoView::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(0.5f, scene, ccWHITE));
}

void MainView::menuFightCallback(CCObject* pSender)
{
	CCScene* scene = FightView::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(0.5f, scene, ccWHITE));
}